package com.ywz.project.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywz.common.ResultResp;
import com.ywz.project.base.system.entity.TSysRole;
import com.ywz.project.base.system.service.TSysRoleService;
import com.ywz.project.system.dto.req.RolePageReq;
import com.ywz.project.system.service.SysRoleApiService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysRoleApiServiceImpl implements SysRoleApiService {
    @Resource
    private TSysRoleService tSysRoleService;

    @Override
    public ResultResp getRolePage(RolePageReq req) {
        LambdaQueryWrapper<TSysRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TSysRole::getIsDeleted, 0);
        Page<TSysRole> page = new Page<>(req.getPageNum(), req.getPageSize());
        return ResultResp.success(tSysRoleService.page(page, queryWrapper));
    }

    @Override
    public ResultResp getRoleListByUserId(Integer userId) {
        List<TSysRole> roleListByUserId = tSysRoleService.getRoleListByUserId(userId);
        return ResultResp.success(roleListByUserId);
    }
}
